package com.cn.wanxi.servlet.designer;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.DesignerModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.service.DesignerService;
import com.cn.wanxi.service.UserService;
import com.cn.wanxi.service.impl.DesignerServiceImpl;
import com.cn.wanxi.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/designer/edit")
public class DesignerEditServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //      0.乱码解决
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //1.得到前端传递过来的数据
        String id = req.getParameter("id");
        String designer_name = req.getParameter("designer_name");
        String sex = req.getParameter("sex");
        String phone = req.getParameter("phone");
        String email = req.getParameter("email");
        String introduce = req.getParameter("introduce");
        String imgHref = req.getParameter("imgHref");
        String enable = req.getParameter("enable");

        //        2.将数据封装到对象
        DesignerModel model = new DesignerModel();
        model.setId(Integer.parseInt(id));
        model.setDesignername(designer_name);
        model.setSex(sex);
        model.setPhone(phone);
        model.setEmail(email);
        model.setIntroduce(introduce);
        model.setImgHref(imgHref);
        model.setEnable(Integer.parseInt(enable));
//        3.调用逻辑层
        DesignerService designerService = new DesignerServiceImpl();

        ResultModel resultModel = designerService.update(model);
        //        4.返回前端需要的数据
        resp.getWriter().print(JSONObject.toJSONString(resultModel));
    }
}
